From 7a914ac673cf5dbd56c501297fd6fab73ecd8581 Mon Sep 17 00:00:00 2001 From: Ewan Mellor Date: Mon, 27 Nov 2006 14:52:41 +0000 Subject: [PATCH] When suspending and resuming, look up the managed path using the domain's UUID. Add a resumed domain to the self.domains list after XendCheckpoint.restore, to ensure that it does not get recreated immediately afterwards. Perform domain_resume under the domains_lock, given that the domain needs to be added. These fixes together should fix xm suspend and xm resume. Signed-off-by: Ewan Mellor --- tools/python/xen/xend/XendDomain.py | 67 ++++++++++++++++------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/tools/python/xen/xend/XendDomain.py b/tools/python/xen/xend/XendDomain.py index 6baa4b7ae4..cdb595131f 100644 --- a/tools/python/xen/xend/XendDomain.py +++ b/tools/python/xen/xend/XendDomain.py @@ -564,8 +564,7 @@ class XendDomain: log.debug('Shutting down domain: %s' % dom.getName()) dom.shutdown("poweroff") elif shutdownAction == 'suspend': - chkfile = self._managed_check_point_path(dom.getName()) - self.domain_save(dom.domid, chkfile) + self.domain_suspend(dom.getName()) finally: self.domains_lock.release() @@ -751,11 +750,13 @@ class XendDomain: if dominfo.state != DOM_STATE_RUNNING: raise XendError("Cannot suspend domain that is not running.") - if not os.path.exists(self._managed_config_path(domname)): + dom_uuid = dominfo.get_uuid() + + if not os.path.exists(self._managed_config_path(dom_uuid)): raise XendError("Domain is not managed by Xend lifecycle " + "support.") - - path = self._managed_check_point_path(domname) + + path = self._managed_check_point_path(dom_uuid) fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC) try: # For now we don't support 'live checkpoint' @@ -774,36 +775,42 @@ class XendDomain: @rtype: None @raise XendError: If failed to restore. """ + self.domains_lock.acquire() try: - dominfo = self.domain_lookup_nr(domname) - - if not dominfo: - raise XendInvalidDomain(domname) + try: + dominfo = self.domain_lookup_nr(domname) - if dominfo.getDomid() == DOM0_ID: - raise XendError("Cannot save privileged domain %s" % domname) + if not dominfo: + raise XendInvalidDomain(domname) - if dominfo.state != DOM_STATE_HALTED: - raise XendError("Cannot suspend domain that is not running.") + if dominfo.getDomid() == DOM0_ID: + raise XendError("Cannot save privileged domain %s" % domname) - chkpath = self._managed_check_point_path(domname) - if not os.path.exists(chkpath): - raise XendError("Domain was not suspended by Xend") + if dominfo.state != DOM_STATE_HALTED: + raise XendError("Cannot suspend domain that is not running.") - # Restore that replaces the existing XendDomainInfo - try: - log.debug('Current DomainInfo state: %d' % dominfo.state) - XendCheckpoint.restore(self, - os.open(chkpath, os.O_RDONLY), - dominfo) - os.unlink(chkpath) - except OSError, ex: - raise XendError("Failed to read stored checkpoint file") - except IOError, ex: - raise XendError("Failed to delete checkpoint file") - except Exception, ex: - log.exception("Exception occurred when resuming") - raise XendError("Error occurred when resuming: %s" % str(ex)) + dom_uuid = dominfo.get_uuid() + chkpath = self._managed_check_point_path(dom_uuid) + if not os.path.exists(chkpath): + raise XendError("Domain was not suspended by Xend") + + # Restore that replaces the existing XendDomainInfo + try: + log.debug('Current DomainInfo state: %d' % dominfo.state) + XendCheckpoint.restore(self, + os.open(chkpath, os.O_RDONLY), + dominfo) + self._add_domain(dominfo) + os.unlink(chkpath) + except OSError, ex: + raise XendError("Failed to read stored checkpoint file") + except IOError, ex: + raise XendError("Failed to delete checkpoint file") + except Exception, ex: + log.exception("Exception occurred when resuming") + raise XendError("Error occurred when resuming: %s" % str(ex)) + finally: + self.domains_lock.release() def domain_create(self, config): -- 2.30.2